package com.renbang.action.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.renbang.model.sys.SysUser;


public class LoginCheckInterceptor extends HandlerInterceptorAdapter {

	/**
	 * 检查是否登陆
	 */
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object obj) throws Exception {

		String requestUrl = request.getRequestURI();
		// 访问非公共路径需要登陆
		if (requestUrl.indexOf("/user/") != -1 || requestUrl.indexOf("/devoloper/") != -1
				|| requestUrl.indexOf("/developer/") != -1) {
			SysUser user = (SysUser) request.getSession().getAttribute("user");
			if (user == null) {
					response.sendRedirect(request.getContextPath() + "/common/login");
				return false;
			} else {
				return true;
			} 
		} else {
			return true;
		}
	}

}
